#!/usr/bin/bash

# read name 
# echo "hello $name"
# n=100
# n=$(($n+1))
# echo "$n"

# declare -i a=100
# a=$a+1
# echo $a

# b=100
# b=`expr $b + 1`
# echo $b

# a=100
# b=200
# c=200

# if test $a -eq $b
# then
#     echo "a 等于 b"
# else
#     echo "a 不等于 b"
# fi


# if [ $c -ne $b ]
# then
#     echo "c 不等于 b"
# else
#     echo "c 等于 b"
# fi

# if [ $a -gt $b ]
# then
#     echo "a 大于 b"
# else
#     echo "a 不大于 b"
# fi

# s2="abc"
# if [ $s1 == $s2 ]
# then
#     echo "s1 等于 s2"
# else
#     echo "s1 不等于 s2"
# fi

# if [ $s1 \< $s2 ]
# then
#     echo "s1 小于 s2"
# else
#     echo "s1 不小于 s2"
# fi

# if [ -z $s1 ]
# then
#     echo "s1 不为空"
# else
#     echo "s1 为空"
# fi

# read -p "请输入一个文件名:" filename

# if [ -e $filename ]
# then
#     echo "文件存在"
# else
#     echo "文件不存在"
# fi

# if [ -s $filename ]
# then
#     echo "文件不为空"
# else
#     echo "文件为空"
# fi

# while true
# do
#     read -p "请输入100以内的一个数:" num
#     if [ $num -eq 100 ]
#     then
#         break
#     fi
# done

# read -p "请输入一个目录名:" dir
# files=`ls $dir`

# cd $dir

# for f in $files
# do
#     if [ -r $f ]
#     then
#         continue
#     fi

#     echo "警告：$f 不可读"
# done

# for v in $@
# do
#     echo $v
# done

# n=1
# while([ $n -le $# ])
# do
#     echo ${!n}
#     n=$(($n+1))
# done

# 用户没有指定文件
if [ $# -eq 0 ]
then
    while true
    do
        read -p "请输入一个文件名:" file

        if [ -z $file ]
        then
            continue
        else
            break
        fi
    done

# 用户指定了文件
else
    file=$1
fi

#判断文件的权限
if [ -e $file ] && [ -r $file ]
then
    echo "文件存在且可读"
elif [ -e $file ]
then
    echo "文件存在但不可读"
else
    echo "文件不存在"
fi